﻿namespace FSpec.TestResources 

open System

type CoinChange() = 
    member x.getChangeFor amount = 
            let coins = [1;2;5;10;20;50;100] 
                        |> List.sortWith(fun a b -> -a.CompareTo(b)) //descending order
                        |> List.filter(fun c -> c <= amount) 
                    
            let rec doWork amount results coins = 
                match coins with
                | [] -> results
                | _ ->
                    let coin = coins.Head
                    let number = amount / coin
                    match number with
                    | 0 -> results
                    | _ -> let remainder = amount % coin
                           let result = String.Format("{0}{1} x {2}c\r\n", results, number, coin)
                           let newCoins = (coins.Tail |> List.filter(fun i -> i <= remainder))
                           doWork remainder result newCoins
                       
            doWork amount "" coins
            